package com.example.demo.service;

import com.example.demo.main.Address;
import com.example.demo.main.AddressExample;
import com.example.demo.mapper.AddressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UseSQLOfAddress {

    @Autowired
    private AddressMapper addressMapper;
    @Autowired
    private AddressExample addressExample;

    public List<Address> selectByUserName(String userName){
        addressExample.clear();
        addressExample.or().andUserNameEqualTo(userName);
        return addressMapper.selectByExample(addressExample);
    }

    public Address selectByUserNameAndRoleFirst(String userName){
        addressExample.clear();
        addressExample.or().andUserNameEqualTo(userName).andRoleEqualTo(1);
        return addressMapper.selectByExample(addressExample).get(0);
    }
}
